package bookstore.util;

import static java.lang.System.out;

import java.util.Scanner;

import bookstore.domain.CODE;
import bookstore.domain.MSG;

public abstract class In {
	private static final Scanner sc;

	static {
		sc = new Scanner(System.in);
	}

	// input string.
	public static String nextLine() {
		return sc.nextLine().trim().intern();
	}

	// input int.
	public static int nextInt() {
		int result = -1;
		try {
			result = Integer.parseInt(nextLine());
		} catch (NumberFormatException e) {	}
		return result;
	}

	// input book code.
	public static int nextCode() {
		int input = -1;
		out.print(MSG.INPUT_BOOK_CODE+"\n>> ");
		try {
			input = Integer.parseInt(nextLine());
			if (input<CODE.BOOK_CODE_MIN || input>CODE.BOOK_CODE_MAX) input = -1;
		} catch (NumberFormatException e) {	}
		return input;
	}

	// input order code.
	public static int nextOrderCode() {
		int input = -1;
		out.print(MSG.INPUT_ORDER_CODE+"\n>> ");
		try {
			input = Integer.parseInt(nextLine());
			if (input<CODE.ORDER_CODE_MIN || input>CODE.ORDER_CODE_MAX) input = -1;
		} catch (NumberFormatException e) {	}		
		return input;
	}
}
